package com.qf.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.qf.mapper.StateMapper;
import com.qf.service.StateService;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class StateServiceImpl implements StateService {
    @Autowired
    StateMapper stateMapper;

    @Override
    public List<CategorySellAmts> findCategoryShell() {
         return stateMapper.findCategoryShell();
    }

    @Override
    public List<DayStatis> findOrderDayStatis() {
        /*Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH,-1);

        Date date = calendar.getTime();

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy--MM--dd 00:00:00");

        String dateStr = simpleDateFormat.format(date);*/

//获取一个月之前的今天
        Calendar calendar = Calendar.getInstance();
        //调整到一个月之前
        calendar.add(Calendar.MONTH, -1);

        Date date = calendar.getTime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        //2022-09-13 00:00:00
        String dateStr = sdf.format(date);



        List<DayStatis>list =  stateMapper.findOrderDayStatis(dateStr);

        return list;
    }

    @Override
    public List<DayStatis> findUserDay() {
        Calendar calendar = Calendar.getInstance();
        //调整到一个月之前
        calendar.add(Calendar.MONTH, -1);

        Date date = calendar.getTime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        //2022-09-13 00:00:00
        String dateStr = sdf.format(date);



        List<DayStatis> list =  stateMapper.findUserdayStatis(dateStr);
        return list;
    }
}
